<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<script type="text/javascript">
			var xmlreq=false;
			function sendRequest(){
				document.getElementById("msg").innerHTML = "正在检测......";
				//创建XMLHttpRequest对象
				if(window.XMLHttpRequest){
					xmlreq=new XMLHttpRequest();
				}else{
					try{
						xmlreq=new ActiveXObject("Msxml2.XMLHTTP");
					}catch(e){
						xmlreq=new ActiveXObject("Microsoft.XMLHTTP");
					}
				}
				var name=document.getElementById("name").value;
				//创建HTTP请求
				//xmlreq.open("get","CheckName?name="+name+"&time="+new Date().getTime(),true);//true表示异步发送请求，默认为true
				//注册响应处理函数
				//xmlreq.onreadystatechange=execute;
				//发送请求
				//xmlreq.send(null);//xmlreq.open("post","url");//post方式发请求.send中要拼url，id=11&name=ui
				//post方法
				xmlreq.open("post","CheckName?time="+new Date().getTime());
				xmlreq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlreq.onreadystatechange=execute;
				xmlreq.send("name="+name);
			}
			//响应处理函数
			function execute(){
				if(xmlreq.readyState==4){
					if(xmlreq.status==200){
						var msg=xmlreq.responseText;
						document.getElementById("msg").innerHTML=msg;
					}else{
						document.getElementById("msg").innerHTML="处理失败";
					}
				}
			}
		</script>
	</head>
	<body>
		校验用户名是否可用<br/>
		<form action="">
			name:<input type="text" onblur="sendRequest()" name="name" id="name"><span id="msg"></span><br/>
			password:<input type="password" name="password" id="password"><br/>
			<input type="submit" value="submit">
		</form>
	</body>
</html>
